package com.qiyun.dinghuohui.common;

import android.os.Environment;
import android.text.TextUtils;
import android.util.Log;
import android.widget.LinearLayout;

import com.qiyun.dinghuohui.ApplicationDataHolder;
import com.qiyun.dinghuohui.utils.LogDebug;
import com.qiyun.dinghuohui.vo.ControlShowCountBean;
import com.qiyun.dinghuohui.vo.LocalSaveOrderListBean;
import com.qiyun.dinghuohui.vo.LocalSaveOrderListOfColorsBean;
import com.qiyun.dinghuohui.vo.ReportDynamicBean;
import com.qiyun.dinghuohui.vo.SizeConfigInfoBean;

import org.apache.http.util.EncodingUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.FileInputStream;
import java.io.FileWriter;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import java.util.TreeMap;

public final class CommonDataSets {

    public static String ALLOWBRAND = "";
    public static List<String> allBrandId = null;
    public static String CLIENT_STRONGPATH = Environment.getExternalStorageDirectory().getPath() +
            "/Android/data/com.qiyun.dinghuohui";//客户端文件存储路径 /data/data/com.quyun.dinghuohui"

    public final static String listAdapterSelectFlag = "current_selectrow";//选中的行
    //公用初始化信息

    public static interface Callback {
        String getValue(String key);
    }

    //AD下线店铺
    public static Map<String, JSONObject> adShopsMapString = new HashMap<String, JSONObject>();

    //颜色说明
    public static List<JSONObject> ds_color_Info = new ArrayList<JSONObject>();

    //配置数据 id,name,value,info1,memo
    public static Map<String, JSONObject> ds_config = new HashMap<String, JSONObject>();
    //排名显示控制
    public static ControlShowCountBean ds_config_activity = new ControlShowCountBean();


    //品牌 s排序,id,brand
    public static List<JSONObject> ds_brand = new ArrayList<JSONObject>();
    //季节 s排序,id,season
    public static Map<String, JSONObject> ds_seasons = new HashMap<String, JSONObject>();
    //系列 s排序,id,serial
    public static Map<String, JSONObject> ds_serials = new HashMap<String, JSONObject>();
    //波段 s排序,id,wave
    public static List<JSONObject> ds_wave = new ArrayList<JSONObject>();
    //大类 s排序,id,type
    public static Map<String, JSONObject> ds_type = new HashMap<String, JSONObject>();
    //小类 s排序,id,style,type
    public static Map<String, JSONObject> ds_style = new HashMap<String, JSONObject>();
    //款式定位 id,v,f
    public static Map<String, JSONObject> ds_goodslevel = new HashMap<String, JSONObject>();


    //尺码 id,type,range
    public static Map<String, JSONObject> ds_sizes = new HashMap<String, JSONObject>();
    //设计师 s排序,id,designer
    public static Map<String, JSONObject> ds_designer = new HashMap<String, JSONObject>();
    //性别 s排序,id,gender
    public static Map<String, JSONObject> ds_gender = new HashMap<String, JSONObject>();
    //颜色 id,category,color,code
    public static Map<String, JSONObject> ds_colors = new HashMap<String, JSONObject>();
    //组织尺码信息
    public static int ds_sizes_maxsizes = 0;
    public static List<ReportDynamicBean> ds_sizes_sizeRangeList = new ArrayList<ReportDynamicBean>();
    //价格带 id,price_range
    public static Map<String, JSONObject> ds_priceRange = new HashMap<String, JSONObject>();

    //货品类别 id,v
    public static Map<String, JSONObject> ds_goodstype = new HashMap<String, JSONObject>();


    //完成率 id name list(region,factStyle,planAmount,factCount,factAmount,planStyle,name,account,planCount)
    public static HashMap<String, Object> wcl_datas = new HashMap<String, Object>();
    //筛选 list(region,factStyle,planAmount,factCount,factAmount,planStyle,name,account,planCount)
    public static List<HashMap<String, String>> sx_datas = new ArrayList<HashMap<String, String>>();

    //从代码表中匹配对应的内容
    public static int getCodeIdByCodeName(Map<String, JSONObject> find_source, String sName, String sFieldName, String sFieldId, int defaultValue) {
        int retValue = defaultValue;
        for (JSONObject jo : find_source.values()) {
            try {
                if (jo.getString(sFieldName).equals(sName)) {
                    retValue = jo.getInt(sFieldId);
                    break;
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        return retValue;
    }

    public static int getCodeIdByCodeName(List<JSONObject> find_source, String sName, String sFieldName, String sFieldId, int defaultValue) {
        int retValue = defaultValue;
        for (JSONObject jo : find_source) {
            try {
                if (jo.getString(sFieldName).equals(sName)) {
                    retValue = jo.getInt(sFieldId);
                    break;
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        return retValue;
    }

    public static String getCodeNameById(Map<String, JSONObject> find_source, int idValue, String sFieldName, String sFieldId, String defaultValue) {
        String retValue = defaultValue;
        for (JSONObject jo : find_source.values()) {
            try {
                if (jo.getInt(sFieldId) == idValue) {
                    retValue = jo.getString(sFieldName);
                    break;
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        return retValue;
    }


    //WIFI id,ssid,pwd
    public static List<JSONObject> ds_wifi = new ArrayList<JSONObject>();

    //获得配置ＷＩＦＩ的连接信息
    public static String getWifiConnectInfoSsid(int wifiid) {
        if (wifiid > 0) {
            wifiid = 1;
        }
        try {
            for (JSONObject jo : ds_wifi) {
                if (jo.getInt("id") == wifiid) {
                    return jo.getString("ssid");
                }
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return "";
    }

    public static String getWifiConnectInfoPwd(int wifiid) {
        if (wifiid > 0) {
            wifiid = 1;
        }
        try {
            for (JSONObject jo : ds_wifi) {
                if (jo.getInt("id") == wifiid) {
                    return jo.getString("pwd");
                }
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return "";
    }

    //区域名称
    public static List<JSONObject> ds_region_name_account = new ArrayList<JSONObject>();

    //商品尺码组  c编号  t类别    s尺码
    public static List<JSONObject> ds_goods_sizegroup = new ArrayList<JSONObject>();

    /**
     * 获得单款尺码组
     */
    public static List<JSONObject> getGoodsSizeGroup(String code) {
        List<JSONObject> retList = new ArrayList<JSONObject>();
        for (JSONObject jo : ds_goods_sizegroup) {
            try {
                if (jo.getString("c").equals(code)) {
                    retList.add(jo);
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        return retList;
    }

    //商品资料  code, stylecode ,goods_code,name,price,price_range_id,intro,material,image_url,season,serial,wave,type,style,designer,gender,must,size_id,size_string,
    //pricetype,freeze,pja,pjb,pjc,pjd,pje,pjf,pjg,pjh,pji,pjj,promotional,star_rqzs,notifyinfo,notifyapply,color_string,color_ids,
    //tyscmlt{同颜色尺码量同},freeze,gl{货品等级},gs{货品类别},gsf{货品类别计算标识},brand, in {比例输入} ,inname {比例名称} ,inmod {比例值修改},
    //cs_f {冻结颜色说明},ci_f {冻结颜色},min{ 最低生产量 }, intc{ 整件数量 }, intn{  整件名称 },pj11,pj12,pj13,pj14,pj15 , picu{图片更新标记}
    public static List<JSONObject> ds_goods = new ArrayList<JSONObject>();
    public static Map<String, JSONObject> ds_goods_map = new HashMap<String, JSONObject>();
    public static Map<Integer, JSONObject> ds_goods_map_code = new TreeMap<>();
    //我的订单
    public static List<JSONObject> ds_orders = new ArrayList<>();
    public static Map<String, JSONObject> ds_orders_map = new HashMap<>();

    public static JSONObject getGoodsByCode(String code) {
        for (JSONObject jo : ds_goods) {
            try {
                if (jo.getString("code").equals(code)) {
                    return jo;
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        return null;
    }


    /**
     * 获得同款号的商品
     */
    public static List<JSONObject> getSameStyleCodeGoods(String stylecode, boolean includecode, String code) {
        List<JSONObject> retList = new ArrayList<JSONObject>();
        for (JSONObject jo : ds_goods) {
            try {
                //判断是否冻结
                if (jo.getString("stylecode").equals(stylecode)) {
                    if (jo.getString("code").equals(code)) {
                        if (includecode) {
                            retList.add(jo);
                        }
                    } else {
                        retList.add(jo);
                    }
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        return retList;
    }


    public static String getWave(String wave) {
        try {
            for (JSONObject jo : ds_wave) {
                if (wave.equals(jo.get("id").toString())) {
                    return jo.getString("wave");
                }
            }
        } catch (Exception e) {
            // TODO: handle exception
        }
        return "";
    }
    //对商品资料进行统计   分析

    //冻洁商品  a,code,color
    public static List<JSONObject> ds_goods_freeze = new ArrayList<JSONObject>();

    public static JSONObject getGoodsFreezeByCodeColor(String code, int color_id) {
        for (JSONObject jo : ds_goods_freeze) {
            try {
                if (jo.getString("code").equals(code) && jo.getInt("color") == color_id) {
                    return jo;
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        return null;
    }

    public static List<JSONObject> ds_sendXiaoxi = new ArrayList<JSONObject>();
    public static List<JSONObject> ds_takeXiaoxi = new ArrayList<JSONObject>();
    public static List<JSONObject> ds_quyu_kehu = new ArrayList<JSONObject>();//区域客户
    //订货，已订
    public static List<JSONObject> goods_order = new ArrayList<JSONObject>();
    //bz内容，bh=code
    public static Map<String, JSONObject> ds_notifyinfo = new HashMap<String, JSONObject>();


    //搭配数据 pair_id,code1,code2,code3,code4,code5,code6,code7,code8,color1,color2,
    // color3,color4,color5,color6,color7,color8,image_url,star_rqzs,st{图片更新}
    public static Map<String, JSONObject> ds_pair = new HashMap<String, JSONObject>();
    //   pair_id,json
    public static Map<String, JSONObject> ds_pair_empy = null;

    //获得搭配数据
    //code
    public static List<JSONObject> getPairsByGoodsCode(String code) {
        List<JSONObject> datalist = new ArrayList<JSONObject>();
        if (code.equals("")) {
            datalist.addAll(ds_pair.values());
        } else {
            for (JSONObject jo : ds_pair.values()) {
                try {
                    if (jo.getString("code1").equals(code) || jo.getString("code2").equals(code) ||
                            jo.getString("code3").equals(code) || jo.getString("code4").equals(code)
                            || jo.getString("code5").equals(code) || jo.getString("code6").equals(code)
                            || jo.getString("code7").equals(code) || jo.getString("code8").equals(code)) {
                        datalist.add(jo);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }
        return datalist;
    }

    //    pair_id
    public static List<JSONObject> getPairsByPairCode(String pairCode) {
        List<JSONObject> datalist = new ArrayList<JSONObject>();
        if (pairCode.equals("")) {
            datalist.addAll(ds_pair.values());
        } else {
            for (JSONObject jo : ds_pair.values()) {
                try {
                    if (pairCode.contains(jo.getString("pair_id"))) {
                        datalist.add(jo);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }
        for (JSONObject jo : datalist) {
            for (String code : ds_orders_map.keySet()) {
                int num = 0;
                List<Boolean> list = new ArrayList<>();
                list.add(jo.optString("code1").equals(code));
                list.add(jo.optString("code2").equals(code));
                list.add(jo.optString("code3").equals(code));
                list.add(jo.optString("code4").equals(code));
                list.add(jo.optString("code5").equals(code));
                list.add(jo.optString("code6").equals(code));
                list.add(jo.optString("code7").equals(code));
                list.add(jo.optString("code8").equals(code));
                for (Boolean b : list) {
                    if (b) {
                        num++;
                    }
                }
                try {
                    jo.put("num", num);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }
        return datalist;
    }

    //    pairgroup
    public static List<JSONObject> getPairsByPairgroup(String pairgroup) {
        List<JSONObject> datalist = new ArrayList<JSONObject>();
        if (pairgroup.equals("")) {
            datalist.addAll(ds_pair.values());
        } else {
            for (JSONObject jo : ds_pair.values()) {
                if (pairgroup.contains(jo.optString("pairgroup"))) {
                    datalist.add(jo);
                }
            }
        }
        for (JSONObject jo : datalist) {
            for (String code : ds_orders_map.keySet()) {
                int num = 0;
                List<Boolean> list = new ArrayList<>();
                list.add(jo.optString("code1").equals(code));
                list.add(jo.optString("code2").equals(code));
                list.add(jo.optString("code3").equals(code));
                list.add(jo.optString("code4").equals(code));
                list.add(jo.optString("code5").equals(code));
                list.add(jo.optString("code6").equals(code));
                list.add(jo.optString("code7").equals(code));
                list.add(jo.optString("code8").equals(code));
                for (Boolean b : list) {
                    if (b) {
                        num++;
                    }
                }
                try {
                    jo.put("num", num);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }
        return datalist;
    }

    //陈列  display,size,c{0..size-1},s{0..size-1},y{0..size-1},rqzs
    public static List<JSONObject> ds_display = new ArrayList<JSONObject>();

    public static List<JSONObject> getDisplaysByCode(String code) {
        List<JSONObject> datalist = new ArrayList<JSONObject>();
        if (code.equals("")) {
            for (JSONObject jo : ds_display) {
                datalist.add(jo);
            }
        } else {
            int i_size = 0;
            boolean bFind = false;
            for (JSONObject jo : ds_display) {
                try {
                    bFind = false;
                    i_size = jo.getInt("size");
                    for (int i = 0; i < i_size; i++) {
                        if (jo.getString("c" + i).equals(code)) {
                            bFind = true;
                            break;
                        }
                    }
                    if (bFind) {
                        datalist.add(jo);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }
        return datalist;
    }

    public static List<JSONObject> ds_display_new = new ArrayList<JSONObject>();

    public static List<JSONObject> getDisplaysByCodeNew(String code) {
        List<JSONObject> datalist = new ArrayList<JSONObject>();
        if (code.equals("")) {
            for (JSONObject jo : ds_display_new) {
                datalist.add(jo);
            }
        } else {
            int i_size = 0;
            boolean bFind = false;
            for (JSONObject jo : ds_display_new) {
                try {
                    bFind = false;
                    i_size = jo.getInt("size");
                    for (int i = 0; i < i_size; i++) {
                        if (jo.getString("c" + i).equals(code)) {
                            bFind = true;
                            break;
                        }
                    }
                    if (bFind) {
                        datalist.add(jo);
                    }
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }
        return datalist;
    }

    //用户订单状态  account,ocs (订单审核状态  0未审核  1已审核不能加单  2已审核可以加单)
    public static List<JSONObject> ds_account_ocs = new ArrayList<JSONObject>();
    //通过displayId获取对应的陈列数据
    public static List<JSONObject> getDisplayNewById(String id) {
        List<JSONObject> list = new ArrayList<>();
        for (JSONObject o : ds_display_new) {
            String display = o.optString("display");
            if (display.equals(id)) {
                list.add(o);
            }
        }
        return list;
    }

    public static int getAccountOrderCheckStatus(int account) {
        int iReturn = 0;
        try {
            for (JSONObject jo : ds_account_ocs) {
                if (jo.getInt("account") == account) {
                    iReturn = jo.getInt("ocs");
                    break;
                }
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return iReturn;
    }

    ////////////////////////////
    //排名数据
    ///////////////////////////
    //总量排名  pm,code,sl
    public static List<JSONObject> ds_sort_groupbycode = new ArrayList<JSONObject>();

    public static int getGroupByCodeAllSortByCode(String code) {
        int ret = -1;
        for (JSONObject jo : ds_sort_groupbycode) {
            try {
                if (jo.getString("code").equals(code)) {
                    ret = jo.getInt("pm");
                    break;
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        return ret;
    }

    public static int getGroupByCodeCountByCode(String code) {
        int ret = 0;
        for (JSONObject jo : ds_sort_groupbycode) {
            try {
                if (jo.getString("code").equals(code)) {
                    ret = jo.getInt("sl");
                    break;
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        return ret;
    }

    //单色排名前30   pm,code,ys{颜色}
    public static List<JSONObject> sort_groupbycolor = new ArrayList<JSONObject>();
    //开放给AD的报表  id,name,method{报表生成方式，3为网页},address{网页地址}
    public static List<JSONObject> ds_report_ad = new ArrayList<JSONObject>();
    //开放给AD的结构分析  id,name
    public static List<JSONObject> ds_struct_ad = new ArrayList<JSONObject>();
    //开放给客户的报表id,name,method{报表生成方式，3为网页},address{网页地址}
    public static List<JSONObject> ds_report_user = new ArrayList<JSONObject>();
    //总代评分 b,r,c,f  {大区，小区，编号，分值}
    public static List<JSONObject> ds_zdpf = new ArrayList<JSONObject>();

    //季节排名 rownum,season_id,serial_id,wave_id,code,sl
    public static Map<String, JSONObject> ds_sort_season = new HashMap<String, JSONObject>();
    //系列排名rownum,serial_id,season_id,wave_id,code,sl
    public static Map<String, JSONObject> ds_sort_serial = new HashMap<String, JSONObject>();
    //波段排名rownum,wave_id,season_id,serial_id,code,sl
    public static Map<String, JSONObject> ds_sort_wave = new HashMap<String, JSONObject>();
    //类别排名rownum,type_id,season_id,serial_id,wave_id,code,sl
    public static Map<String, JSONObject> ds_sort_type = new HashMap<String, JSONObject>();
    //款式排名rownum,style_id,season_id,serial_id,wave_id,type_id,code,sl
    public static Map<String, JSONObject> ds_sort_style = new HashMap<String, JSONObject>();
    //价格带排名rownum,price_range_id,season_id,serial_id,wave_id,style_id,code,sl
    public static Map<String, JSONObject> ds_sort_price = new HashMap<String, JSONObject>();
    //颜色排名rownum,color_id,season_id,serial_id,wave_id,style_id,code,sl
    public static Map<String, JSONObject> ds_sort_color = new HashMap<String, JSONObject>();
    //尺码排名rownum,size_sub_id,season_id,serial_id,wave_id,style_id,code,sl
    public static Map<String, JSONObject> ds_sort_size = new HashMap<String, JSONObject>();

    public static List<JSONObject> getGooosList() {
        List<JSONObject> listGoods = new ArrayList<>();
        for (JSONObject ds_good : CommonDataSets.ds_goods) {
            listGoods.add(ds_good);
        }
        return listGoods;
    }

    //在map中通过筛选条件获取筛选数据
    public static List<JSONObject> getSxDataByMap(Map<String, JSONObject> map) {

        if (map.size() != 0) {
            String[] keys = new String[]{"brand", "season", "serial", "wave", "type", "style", "v", "全部"};

            List<JSONObject> list = getGooosList();
            for (Object o : map.entrySet()) {
                Map.Entry entry = (Map.Entry) o;
                String key = (String) entry.getKey();
                JSONObject value = (JSONObject) entry.getValue();
                if (key.equals(keys[0])) {
                    String name = value.optString("name");
                    if (!name.equals(keys[7])) {
                        String band1 = value.optString("id");
                        ListIterator<JSONObject> iterator = list.listIterator();
                        while (iterator.hasNext()) {
                            JSONObject object = iterator.next();
                            String value1 = object.optString(keys[0]);
                            if (!value1.equals(band1)) {
                                iterator.remove();
                            }
                        }
                    }
                }
                if (key.equals(keys[1])) {
                    String name = value.optString("name");
                    if (!name.equals(keys[7])) {
                        String band1 = value.optString("id");
                        ListIterator<JSONObject> iterator = list.listIterator();
                        while (iterator.hasNext()) {
                            JSONObject object = iterator.next();
                            String value1 = object.optString(keys[1]);
                            if (!value1.equals(band1)) {
                                iterator.remove();
                            }
                        }
                    }
                }
                if (key.equals(keys[2])) {
                    String name = value.optString("name");
                    if (!name.equals(keys[7])) {
                        String band1 = value.optString("id");
                        ListIterator<JSONObject> iterator = list.listIterator();
                        while (iterator.hasNext()) {
                            JSONObject object = iterator.next();
                            String value1 = object.optString(keys[2]);
                            if (!value1.equals(band1)) {
                                iterator.remove();
                            }
                        }
                    }
                }
                if (key.equals(keys[3])) {
                    String name = value.optString("name");
                    if (!name.equals(keys[7])) {
                        String band1 = value.optString("id");
                        ListIterator<JSONObject> iterator = list.listIterator();
                        while (iterator.hasNext()) {
                            JSONObject object = iterator.next();
                            String value1 = object.optString(keys[3]);
                            if (!value1.equals(band1)) {
                                iterator.remove();
                            }
                        }
                    }
                }
                if (key.equals(keys[4])) {
                    String name = value.optString("name");
                    if (!name.equals(keys[7])) {
                        String band1 = value.optString("id");
                        ListIterator<JSONObject> iterator = list.listIterator();
                        while (iterator.hasNext()) {
                            JSONObject object = iterator.next();
                            String value1 = object.optString(keys[4]);
                            if (!value1.equals(band1)) {
                                iterator.remove();
                            }
                        }
                    }
                }
                if (key.equals(keys[5])) {
                    String name = value.optString("name");
                    if (!name.equals(keys[7])) {
                        String band1 = value.optString("id");
                        ListIterator<JSONObject> iterator = list.listIterator();
                        while (iterator.hasNext()) {
                            JSONObject object = iterator.next();
                            String value1 = object.optString(keys[5]);
                            if (!value1.equals(band1)) {
                                iterator.remove();
                            }
                        }
                    }
                }
                if (key.equals(keys[6])) {
                    String name = value.optString("name");
                    if (!name.equals(keys[7])) {
                        String band1 = value.optString("id");
                        ListIterator<JSONObject> iterator = list.listIterator();
                        while (iterator.hasNext()) {
                            JSONObject object = iterator.next();
                            String value1 = object.optString(keys[6]);
                            if (!value1.equals(band1)) {
                                iterator.remove();
                            }
                        }
                    }
                }
            }
            return list;
        } else {
            return getGooosList();
        }
    }

    //获取总款数
    public static String getOrderKColor() {
        //我的订单orders里count和
        List<JSONObject> orderList = CommonDataSets.ds_orders;
        HashSet<String> colors = new HashSet<>();
        for (JSONObject object : orderList) {
            String count = object.optString("color_id");
            colors.add(count);
        }
        return String.valueOf(colors.size());
    }

    //获取总款数
    public static String getOrderKuan() {
        //我的订单orders里count和
        List<JSONObject> orderList = CommonDataSets.ds_orders;
        HashSet<String> codes = new HashSet<>();
        for (JSONObject object : orderList) {
            String count = object.optString("code");
            codes.add(count);
        }
        return String.valueOf(codes.size());
    }

    //获取总件数
    public static String getOrderCount() {
        //我的订单orders里count和
        int num = 0;
        List<JSONObject> orderList = CommonDataSets.ds_orders;
        for (JSONObject object : orderList) {
            String count = object.optString("count", "0");
            int a = Integer.parseInt(count);
            num += a;
        }
        return String.valueOf(num);
    }

    //获取总件数的金额
    public static String getOrdersMoney() {
        int money = 0;
        List<JSONObject> goosList = CommonDataSets.ds_goods;
        for (JSONObject object : goosList) {
            int count = Integer.parseInt(object.optString("count", "0"));
            if (count > 0) {
                int price = Integer.parseInt(object.optString("price"));
                int perOrder = count * price;
                money += perOrder;
            }
        }
        return String.valueOf(money);
    }



    //将订单数据中数量同步到商品信息中
    public static void saveToCacheBaseData_order(JSONObject jsonData) throws JSONException {
        JsonWrap json = new JsonWrap(jsonData);
        ds_orders.clear();
        if (jsonData != null && jsonData.length() != 0) {
            populateObject(json.getJSONArray("data"), ds_orders);
            populateObject(json.getJSONArray("data"), ds_orders_map, "code");
            if (ds_goods_map.size() != 0) {
                for (Object g : ds_goods_map.entrySet()) {
                    Map.Entry entry1 = (Map.Entry) g;
                    String key1 = (String) entry1.getKey();
                    JSONObject pair1 = (JSONObject) entry1.getValue();
                    int num = 0;
                    for (JSONObject o : ds_orders) {
                        String key2 = o.optString("code");
                        if (key2.equals(key1)) {
                            String count = o.getString("count");
                            int a = Integer.parseInt(count);
                            num += a;
                        }
                    }
                    String count = String.valueOf(num);
                    pair1.put("count", count);
                }

                mapToArray(ds_goods_map);
            }
        } else {
            for (Object g : ds_goods_map.entrySet()) {
                Map.Entry entry1 = (Map.Entry) g;
                JSONObject pair1 = (JSONObject) entry1.getValue();
                pair1.put("count", String.valueOf(0));
            }
            mapToArray(ds_goods_map);
        }
    }

    //商品信息转换为Array
    public static void mapToArray(Map<String, JSONObject> ds_goods_map) {
        ds_goods.clear();
        for (Object g : ds_goods_map.entrySet()) {
            Map.Entry entry1 = (Map.Entry) g;
            JSONObject pair1 = (JSONObject) entry1.getValue();
            ds_goods.add(pair1);
        }
    }

    public static void saveToCacheBaseData_g(JSONObject jsonData) throws JSONException {
        JsonWrap json = new JsonWrap(jsonData);
        ds_goods.clear();
        ds_goods_map.clear();
        if (allBrandId == null) {
            populateObject(json.getJSONArray("goods"), ds_goods);
            populateObject(json.getJSONArray("goods"), ds_goods_map, "code");
            populateCode(json.getJSONArray("goods"), ds_goods_map_code);
        } else {
            JSONArray goodsArray = json.getJSONArray("goods");
            if (goodsArray != null) {
                int len = goodsArray.length();
                int brandId = allBrandId.size();
                for (int i = 0; i < len; i++) {
                    JSONObject object = (JSONObject) goodsArray.get(i);
                    //这个地方进行判断
                    for (int j = 0; j < brandId; j++) {
                        if (allBrandId.get(j).endsWith(object.getString("brand"))) {
                            ds_goods.add(object);
                        }
                    }
                }

                if (ds_goods != null) {
                    for (JSONObject jo : ds_goods) {
                        ds_goods_map.put(jo.getString("code"), jo);
                        ds_goods_map_code.put(Integer.parseInt(jo.getString("code")), jo);
                    }
                }
            }
            //搭配数据部分
            if (ds_pair_empy != null) {
                for (Object o : ds_pair_empy.entrySet()) {
                    Map.Entry entry = (Map.Entry) o;
                    Object key = entry.getKey();
                    JSONObject pair = (JSONObject) entry.getValue();
                    boolean delete = true;
                    for (int k = 1; k < 9; k++) {
                        String code = pair.getString("code" + k);
                        if (TextUtils.isEmpty(code)) continue;
                        JSONObject result = getGoodsByCode(code);
                        if (result == null) {
                            delete = false;
                            break;
                        }
                    }
                    if (delete) {
                        ds_pair.put(key.toString(), pair);
                    }
                }
            }

        }
    }

    public static void saveToCacheBaseData2(ApplicationDataHolder adh, JSONObject jsonObject) {
        try {
            String id = "";
            wcl_datas.clear();
            sx_datas.clear();
            if (jsonObject.has("allSeason")) {
                JSONArray allSeasonArray = jsonObject.getJSONArray("allSeason");
                List<HashMap<String, String>> allSeasonList = new ArrayList<HashMap<String, String>>();
                for (int i = 0; i < allSeasonArray.length(); i++) {
                    JSONObject allSeasonObject = allSeasonArray.getJSONObject(i);
                    HashMap<String, String> hashMap = new HashMap<String, String>();
                    hashMap.put("id", getjsonString(allSeasonObject, "id"));
                    hashMap.put("name", getjsonString(allSeasonObject, "name"));
                    if (getjsonString(allSeasonObject, "name").contains("所有")) {
                        id = getjsonString(allSeasonObject, "id");
                    }
                    allSeasonList.add(hashMap);
                }
                wcl_datas.put("allSeason", allSeasonList);
            }
            if (jsonObject.has("data")) {
                JSONArray dataArray = jsonObject.getJSONArray("data");
                List<HashMap<String, Object>> dataList = new ArrayList<HashMap<String, Object>>();
                for (int i = 0; i < dataArray.length(); i++) {
                    JSONObject dataObject = dataArray.getJSONObject(i);
                    HashMap<String, Object> dataMap = new HashMap<String, Object>();
                    dataMap.put("id", getjsonString(dataObject, "id"));
                    if (dataObject.has("dataSon")) {
                        JSONArray dataSonArray = dataObject.getJSONArray("dataSon");
                        List<HashMap<String, String>> dataSonList = new ArrayList<HashMap<String, String>>();
                        for (int j = 0; j < dataSonArray.length(); j++) {
                            JSONObject dataSonObject = dataSonArray.getJSONObject(j);
                            HashMap<String, String> dataSonMap = new HashMap<String, String>();
                            dataSonMap.put("region", getjsonString(dataSonObject, "region"));
                            dataSonMap.put("factStyle", getjsonString(dataSonObject, "factStyle"));
                            dataSonMap.put("planAmount", getjsonString(dataSonObject, "planAmount"));
                            dataSonMap.put("factCount", getjsonString(dataSonObject, "factCount"));
                            dataSonMap.put("factAmount", getjsonString(dataSonObject, "factAmount"));
                            dataSonMap.put("planStyle", getjsonString(dataSonObject, "planStyle"));
                            dataSonMap.put("name", getjsonString(dataSonObject, "name"));
                            dataSonMap.put("account", getjsonString(dataSonObject, "account"));
                            dataSonMap.put("planCount", getjsonString(dataSonObject, "planCount"));
                            if (adh.getMemo() != null && adh.getMemo()[0] != null && CommonDataSets.getIntforString(adh.getMemo()[0], -1) >= 0) {
                                boolean canadd = false;
                                for (int k = 0; k < adh.getMemo().length; k++) {
                                    if (getjsonString(dataSonObject, "account").equals(adh.getMemo()[k])) {
                                        canadd = true;
                                        break;
                                    }
                                }
                                if (canadd) {
                                    dataSonList.add(dataSonMap);
                                }
                            } else {
                                dataSonList.add(dataSonMap);
                            }


                        }
                        dataMap.put("dataSon", dataSonList);
                        if (id.equals(getjsonString(dataObject, "id"))) {
                            sx_datas.addAll(dataSonList);
                        }
                    }
                    dataList.add(dataMap);
                }

                wcl_datas.put("data", dataList);
            }
        } catch (Exception e) {
            ApplicationDataHolder.Trace("@@eee完成率eee= " + e.toString());
        }
    }

    // 专门用于判断字段是否存在的直接解析的函数
    public static String getjsonString(JSONObject jsonObject, String key) {
        try {
            if (jsonObject.has(key)) {
                return jsonObject.getString(key);
            }
        } catch (Exception e) {
            // TODO: handle exception
            return "";
        }
        return "";
    }

    public static void saveToCacheBaseData(JSONObject jsonData) throws JSONException {
        JsonWrap json = new JsonWrap(jsonData);
        ds_config.clear();
        populateObject(json.getJSONArray("config"), ds_config, "id");
        if (ds_config.get("3") != null) {
            ds_config_activity.picModal = ds_config.get("3").getInt("value");
            Log.d("", "ds_config_activity.picModal->" + ds_config_activity.picModal);
        }
        JSONArray array = json.getJSONArray("config_activity");
        if (array.length() > 0) {
            JSONObject object = (JSONObject) array.get(0);
            ds_config_activity.netOpen = object.getInt("netopen") == 1;
            ds_config_activity.netOpenMinute = object.getInt("netopenminute");
            ds_config_activity.netAutoChange = object.getInt("netauto") == 1;

            ds_config_activity.seasonCount = object.getInt("season");
            ds_config_activity.serialCount = object.getInt("serial");
            ds_config_activity.serialFreeze = object.getInt("serialf") == 1;
            ds_config_activity.waveCount = object.getInt("wave");
            ds_config_activity.waveFreeze = object.getInt("wavef") == 1;
            ds_config_activity.typeCount = object.getInt("type");
            ds_config_activity.typeFreeze = object.getInt("typef") == 1;
            ds_config_activity.styleCount = object.getInt("style");
            ds_config_activity.styleFreeze = object.getInt("stylef") == 1;
            ds_config_activity.priceCount = object.getInt("price");
            ds_config_activity.priceFreeze = object.getInt("pricef") == 1;

            ds_config_activity.showsortall = object.getInt("showsortall") == 1;
            ds_config_activity.showsortarea = object.getInt("showsortarea") == 1;
            ds_config_activity.showbigpic = object.getInt("showbigpic") == 1;

            ds_config_activity.wifilowervalue = object.getInt("wifilowervalue");
            ds_config_activity.qdlfull = object.getInt("qdlfull") == 1;
            ds_config_activity.qdlcanclear = object.getInt("qdlcanclear") == 1;
            ds_config_activity.qdlsuggest = object.getInt("qdlsuggest") == 1;
            ds_config_activity.seasoncancelselall = object.getInt("seasoncancelselall") == 1;
            ds_config_activity.showsale = object.getInt("showsale") == 1;
            ds_config_activity.showjhj = object.getInt("showjhj") == 1;
            ds_config_activity.showjhjcalc = object.getInt("showjhjcalc") == 1;
            ds_config_activity.showzdpf = object.getInt("showzdpf") == 1;
            ds_config_activity.showzdpfall = object.getInt("showzdpfall") == 1;
            ds_config_activity.showzdpfbig = object.getInt("showzdpfbig") == 1;
            ds_config_activity.showzdpfsmall = object.getInt("showzdpfsmall") == 1;
            ds_config_activity.cfilterkh = object.getInt("cfilterkh") == 1;
            ds_config_activity.opendelbef = object.getInt("opendelbef") == 1;
            ds_config_activity.httpanaly = object.getString("httpanaly");

            ds_config_activity.updatefail = object.getInt("updatefail") == 1;
            ds_config_activity.updatefailcount = object.getInt("updatefailcount");
            ds_config_activity.dcdl = object.getInt("dcdl") == 1;
            ds_config_activity.dcdllower = object.getInt("dcdllower");
            ds_config_activity.clientcheck = object.getInt("clientcheck") == 1;
            ds_config_activity.clientautobase = object.getInt("clientautobase") == 1;
            ds_config_activity.httpurl = object.getString("httpurl");
            ds_config_activity.display = object.getString("display");
        }
        ds_brand.clear();
        if ("全部".equalsIgnoreCase(ALLOWBRAND) || "".equals(ALLOWBRAND)) {
            populateObject(json.getJSONArray("brand"), ds_brand);
            if (allBrandId != null) allBrandId = null;
        } else {
            allBrandId = new ArrayList<String>();
            JSONArray brandArray = json.getJSONArray("brand");
            if (brandArray != null) {
                int len = brandArray.length();
                for (int i = 0; i < len; i++) {
                    JSONObject object = (JSONObject) brandArray.get(i);
                    if (ALLOWBRAND.contains(object.optString("brand"))) {
                        allBrandId.add(object.optString("id"));
                        ds_brand.add(object);
                    }
                }
            }
        }

        ds_color_Info.clear();
        populateObject(json.getJSONArray("sexi_t"), ds_color_Info);
        ds_seasons.clear();
        populateObject(json.getJSONArray("season"), ds_seasons, "id");
        ds_serials.clear();
        populateObject(json.getJSONArray("serial"), ds_serials, "id");
        ds_wave.clear();
        populateObject(json.getJSONArray("wave"), ds_wave, "s");
        ds_type.clear();
        populateObject(json.getJSONArray("type"), ds_type, "id");
        ds_style.clear();
        populateObject(json.getJSONArray("style"), ds_style, "id");
        ds_designer.clear();
        populateObject(json.getJSONArray("designer"), ds_designer, "id");
        ds_gender.clear();
        populateObject(json.getJSONArray("gender"), ds_gender, "id");
        ds_colors.clear();
        populateObject(json.getJSONArray("color"), ds_colors, "id");
        ds_sizes.clear();
        populateObject(json.getJSONArray("size"), ds_sizes, "id");
        //尺码信息
        ds_sizes_maxsizes = 0;
        ds_sizes_sizeRangeList.clear();
        ReportDynamicBean rdbTemp;
        for (JSONObject jo : ds_sizes.values()) {
            String[] rangeSplit = jo.getString("range").split(",");
            rdbTemp = new ReportDynamicBean();
            rdbTemp.setRowNum(rangeSplit.length);
            rdbTemp.setItem0(jo.getString("id"));
            rdbTemp.setItem1(jo.getString("type"));
            if (ds_sizes_maxsizes < rdbTemp.getRowNum()) {
                ds_sizes_maxsizes = rdbTemp.getRowNum();
            }
            for (int i = 0; i < rangeSplit.length; i++) {
                ApplicationDataHolder.Trace("@@@size= " + i + "==" + rangeSplit[i]);
                rdbTemp.setItemIndex(i + 2, rangeSplit[i]);
            }
            ds_sizes_sizeRangeList.add(rdbTemp);
        }

        ds_region_name_account.clear();
        populateObject(json.getJSONArray("khinfo"), ds_region_name_account);

        ds_goods_sizegroup.clear();
        populateObject(json.getJSONArray("goodssizegroup"), ds_goods_sizegroup);

        ds_priceRange.clear();
        populateObject(json.getJSONArray("price_range"), ds_priceRange, "id");
        ds_goodslevel.clear();
        populateObject(json.getJSONArray("goodslevel"), ds_goodslevel, "id");
        ds_goodstype.clear();
        populateObject(json.getJSONArray("goodstype"), ds_goodstype, "id");
        ds_wifi.clear();
        populateObject(json.getJSONArray("wifi"), ds_wifi);

        ds_goods_freeze.clear();
        populateObject(json.getJSONArray("goods_freeze"), ds_goods_freeze);
        ds_notifyinfo.clear();
        populateObject(json.getJSONArray("notifyinfo"), ds_notifyinfo, "bh");
        ds_takeXiaoxi.clear();
        populateObject(json.getJSONArray("taketongzhi"), ds_takeXiaoxi);
        ds_sendXiaoxi.clear();
        populateObject(json.getJSONArray("sendtongzhi"), ds_sendXiaoxi);
        ds_pair.clear();
        // "ALLOWBRAND": "摩亚小作,帕纳摩亚",
        if ("全部".equalsIgnoreCase(ALLOWBRAND) || "".equals(ALLOWBRAND)) {
            populateObject(json.getJSONArray("pairs"), ds_pair, "pair_id");
            ds_pair_empy = null;
        } else {
            ds_pair_empy = new HashMap<String, JSONObject>();
            populateObject(json.getJSONArray("pairs"), ds_pair_empy, "pair_id");
        }
        ds_display.clear();
        populateObject(json.getJSONArray("displays"), ds_display);
        ds_display_new.clear();
        populateObject(json.getJSONArray("displays_new"), ds_display_new);
        ds_sort_groupbycode.clear();
        populateObject(json.getJSONArray("sort_groupbycode"), ds_sort_groupbycode);
        sort_groupbycolor.clear();
        populateObject(json.getJSONArray("sort_groupbycolor"), sort_groupbycolor);
        ds_account_ocs.clear();
        populateObject(json.getJSONArray("account_ocs"), ds_account_ocs);
        ds_report_ad.clear();
        populateObject(json.getJSONArray("ad_reportlist"), ds_report_ad);
        ds_struct_ad.clear();
        populateObject(json.getJSONArray("ad_structlist"), ds_struct_ad);
        ds_report_user.clear();
        populateObject(json.getJSONArray("user_reportlist"), ds_report_user);
        ds_zdpf.clear();
        populateObject(json.getJSONArray("zdpf"), ds_zdpf);
        ds_sort_season.clear();
        populateObject(json.getJSONArray("sort_season"), ds_sort_season, "rownum");
        ds_sort_serial.clear();
        populateObject(json.getJSONArray("sort_serial"), ds_sort_serial, "rownum");
        ds_sort_wave.clear();
        populateObject(json.getJSONArray("sort_wave"), ds_sort_wave, "rownum");
        ds_sort_type.clear();
        populateObject(json.getJSONArray("sort_type"), ds_sort_type, "rownum");
        ds_sort_style.clear();
        populateObject(json.getJSONArray("sort_style"), ds_sort_style, "rownum");
        ds_sort_price.clear();
        populateObject(json.getJSONArray("sort_price"), ds_sort_price, "rownum");
        ds_sort_color.clear();
        populateObject(json.getJSONArray("sort_color"), ds_sort_color, "rownum");
        ds_sort_size.clear();
        populateObject(json.getJSONArray("sort_size"), ds_sort_size, "rownum");
    }

    ////////////////////////////
    //
    //  动态数据 根据客户而订  下线客户、标记数据，订单数据
    //
    ///////////////////////////
    //下线客户  account,name,priviledge
    public static Map<String, JSONObject> ds_user_list = new HashMap<String, JSONObject>();
    //计划额  item0=pa item1=pc item2=ps
    public static ReportDynamicBean ds_user_plan_all = new ReportDynamicBean();
    //b,s,pa,pc,ps
    public static List<JSONObject> ds_user_plan = new ArrayList<JSONObject>();

    //用户起订量配置 code,color,size,mincount
    public static List<JSONObject> ds_user_configmincolor = new ArrayList<JSONObject>();

    public static List<JSONObject> getConfigMinColorCountByCode(String code) {
        List<JSONObject> map = new ArrayList<JSONObject>();
        for (JSONObject jo : ds_user_configmincolor) {
            try {
                if (jo.getString("code").equals(code)) {
                    map.add(jo);
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        return map;
    }

    //用户建议标准值  br{ 品牌 },sa{ 季节 },se{ 系列 },wa{ 波段 },st{ 款式 },gn{ 性别 },susc{ 建议款 },suc{ 建议量 },sua{ 建议额 }
    public static List<JSONObject> ds_user_suggest = new ArrayList<JSONObject>();

    public static ReportDynamicBean getUserSuggestGroup(int br, int sa, int se, int wa, int st, int gn) {
        ReportDynamicBean beanRet = new ReportDynamicBean();
        beanRet.setDatavalib(true);
        beanRet.setItem0("0"); //款
        beanRet.setItem1("0"); //量
        beanRet.setItem2("0"); //金额
        for (JSONObject jo : ds_user_suggest) {
            try {
                if ((br == jo.getInt("br") || br <= 0) && (sa == jo.getInt("sa") || sa <= 0) && (se == jo.getInt("se") || se <= 0) && (wa == jo.getInt("wa") || wa <= 0)
                        && (st == jo.getInt("st") || st <= 0) && (gn == jo.getInt("gn") || gn <= 0)) {
                    beanRet.setItem0(String.valueOf(CommonDataSets.getIntforString(beanRet.getItem0()) + jo.getInt("susc")));
                    beanRet.setItem1(String.valueOf(CommonDataSets.getIntforString(beanRet.getItem1()) + jo.getInt("suc")));
                    beanRet.setItem2(String.valueOf(CommonDataSets.getIntforString(beanRet.getItem2()) + jo.getInt("sua")));
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }

        return beanRet;
    }

    //标记数据  account,code,flag_mark,flag_fh,wifichange,savetime,sync,sug ( 意见 )  ,read ( 修改通知阅读标志 )
    public static Map<String, JSONObject> ds_user_goods_flag = new HashMap<String, JSONObject>();

    //判断有未同步的标记数据
    public static JSONArray getGoodsFlagNotSync() {
        JSONArray returnList = new JSONArray();
        JSONObject map = null;

        for (JSONObject jo : ds_user_goods_flag.values()) {
            try {
                if (jo.getInt("sync") == 2) {
                    jo.put("sync", 0);
                }
                if (jo.getInt("sync") == 0) {//未同步
                    map = new JSONObject();
                    map.put("account", jo.getString("account"));
                    map.put("code", jo.getString("code"));
                    map.put("flag_mark", jo.getString("flag_mark_sync"));
                    map.put("flag_fh", jo.getString("flag_fh_sync"));
                    map.put("code_wifichange", jo.getString("code_wifichange"));
                    map.put("code_savetime", jo.getString("code_savetime"));
                    map.put("sug", jo.getString("sug"));
                    map.put("read", jo.getString("read"));
                    returnList.put(map);
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        return returnList;
    }

    public static JSONArray getGoodsFlagNotSyncAll() {
        JSONArray returnList = new JSONArray();
        JSONObject map = null;

        for (JSONObject jo : ds_user_goods_flag.values()) {
            try {
                map = new JSONObject();
                map.put("account", jo.getString("account"));
                map.put("code", jo.getString("code"));
                map.put("flag_mark", jo.getString("flag_mark_sync"));
                map.put("flag_fh", jo.getString("flag_fh_sync"));
                map.put("code_wifichange", jo.getString("code_wifichange"));
                map.put("code_savetime", jo.getString("code_savetime"));
                map.put("sug", jo.getString("sug"));
                map.put("read", jo.getString("read"));
                returnList.put(map);
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        return returnList;
    }

    //陈列标记  display,mark,mark_sync
    public static Map<String, JSONObject> ds_user_goods_display_flag = new HashMap<String, JSONObject>();

    //判断有无同步的标记数据
    public static JSONArray getGoodsDisplayFlagNotSync() {
        JSONArray returnList = new JSONArray();
        JSONObject map = null;

        for (JSONObject jo : ds_user_goods_display_flag.values()) {
            try {
                if (jo.getInt("sync") == 2) {
                    jo.put("sync", 0);
                }
                if (jo.getInt("sync") == 0) {//未同步
                    map = new JSONObject();
                    map.put("display", jo.getString("display"));
                    map.put("mark", jo.getString("mark_sync"));
                    returnList.put(map);
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        return returnList;
    }

    public static JSONArray getGoodsDisplayFlagNotSyncAll() {
        JSONArray returnList = new JSONArray();
        JSONObject map = null;

        for (JSONObject jo : ds_user_goods_display_flag.values()) {
            try {
                map = new JSONObject();
                map.put("display", jo.getString("display"));
                map.put("mark", jo.getString("mark_sync"));
                returnList.put(map);
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        return returnList;
    }

    public static JSONObject getOrderShowConfigNotSync() {
        if (ds_config_activity.orderShowConfigSync) {
            JSONObject retJson = new JSONObject();
            try {
                retJson.put("ossync", 1);
                retJson.put("account", ds_config_activity.orderShowAccount);
                retJson.put("ospic", ds_config_activity.orderShowPic ? 1 : 0);
                retJson.put("osseason", ds_config_activity.orderShow_Season ? 1 : 0);
                retJson.put("osserial", ds_config_activity.orderShow_Serial ? 1 : 01);
                retJson.put("oswave", ds_config_activity.orderShow_Wave ? 1 : 0);
                retJson.put("ostype", ds_config_activity.orderShow_Type ? 1 : 0);
                retJson.put("osstyle", ds_config_activity.orderShow_Style ? 1 : 0);
                retJson.put("osstylepos", ds_config_activity.orderShow_StylePos ? 1 : 0);
                retJson.put("osprice", ds_config_activity.orderShow_Price ? 1 : 0);
                retJson.put("oscolor", ds_config_activity.orderShow_Color ? 1 : 0);
                return retJson;
            } catch (JSONException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        return null;
    }

    //订单尺码组  a账号  c编号  t尺码组  s颜色  l数量 ls待同步数据  sync同步
    public static List<JSONObject> ds_user_order_sizegroup = new ArrayList<JSONObject>();

    public static void goodsOrderSizeGroupSave(int account, String code, String st, int color, int ls) {
        boolean isFind = false;
        try {
            for (JSONObject jo : ds_user_order_sizegroup) {
                if (jo.getInt("a") == account && jo.getString("c").equals(code) && jo.getString("t").equals(st) && jo.getInt("s") == color) {
                    jo.put("ls", ls);
                    jo.put("sync", 2);
                    isFind = true;
                }
            }
            if (!isFind) {
                JSONObject jobj = new JSONObject();
                jobj.put("a", account);
                jobj.put("c", code);
                jobj.put("t", st);
                jobj.put("s", color);
                jobj.put("l", ls);
                jobj.put("ls", ls);
                jobj.put("sync", 2);
                ds_user_order_sizegroup.add(jobj);
            }
            Log.d("", "account->" + account + " code->" + code + " st->" + st + " ls->" + ls + " color->" + color + "  isFind->" + isFind);
        } catch (JSONException e) {
            e.printStackTrace();
        }

    }

    public static List<JSONObject> getGoodsOrderSizeGroup(String code) {
        List<JSONObject> retList = new ArrayList<JSONObject>();
        for (JSONObject jo : ds_user_order_sizegroup) {
            try {
                if (jo.getString("c").equals(code)) {
                    retList.add(jo);
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        return retList;
    }

    public static JSONArray getOrderSizeGroupNotSync() {
        JSONArray returnList = new JSONArray();
        JSONObject map = null;
        for (JSONObject jo : ds_user_order_sizegroup) {
            try {
                if (jo.getInt("sync") == 2) {
                    jo.put("sync", 0);
                }
                if (jo.getInt("sync") == 0) {//未同步
                    map = new JSONObject();
                    map.put("a", jo.getString("a"));
                    map.put("c", jo.getString("c"));
                    map.put("t", jo.getString("t"));
                    map.put("s", jo.getString("s"));
                    map.put("l", jo.getString("ls"));
                    returnList.put(map);
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        return returnList;
    }

    //订单数据 account,code,count,dp,sj,size_id,size_sub_id,color_id,freeze,sync
    //TODO:改进成使用二级存储 关键字使用 account+"#"+code
    public static Map<String, LocalSaveOrderListBean> ds_user_order = new HashMap<String, LocalSaveOrderListBean>();

    //获得指定商品的计单列表
    public static LocalSaveOrderListBean getGoodsOrdersByCode(int account, String code, boolean bNullCreate) {
        LocalSaveOrderListBean orderlist = ds_user_order.get(account + "#" + code);
        if (orderlist == null && bNullCreate) {
            orderlist = new LocalSaveOrderListBean();
        }
        return orderlist;
    }

    public static void userDataClearSyncFlagForOrder(int account, String code) {
        for (LocalSaveOrderListBean orderitem : ds_user_order.values()) {
            for (LocalSaveOrderListOfColorsBean coloritem : orderitem.getColors()) {
                if (coloritem.getSync() != 1) {
                    coloritem.setCount(coloritem.getCountOld());
                    coloritem.setSync(1);
                }
            }
        }

    }

    //本区域总量排名 pm,code,sl
    public static List<JSONObject> ds_user_areasort_groupbycode = new ArrayList<JSONObject>();

    public static int getGroupByCodeAreaSortByCode(String code) {
        int ret = -1;
        for (JSONObject jo : ds_user_areasort_groupbycode) {
            try {
                if (jo.getString("code").equals(code)) {
                    ret = jo.getInt("pm");
                    break;
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        return ret;
    }

    //配码  a,t,s,st,si,sn,sr,ct,y  { 账号,类型,款式,尺码类别,尺码ID,尺寸,排序,值,同步标记 }
    public static List<JSONObject> ds_user_configcode = new ArrayList<JSONObject>();

    public static JSONArray getUserConfigCodeNotSync() {
        JSONArray returnList = new JSONArray();
        for (JSONObject jo : ds_user_configcode) {
            try {
                if (jo.getInt("y") == 2) {
                    jo.put("y", 0);
                }
                if (jo.getInt("y") == 0) {
                    returnList.put(jo);
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        return returnList;
    }

    //根据编号查询
    public static List<JSONObject> getConfigCodeByStyle(int showType, int style, int sizeid) {
        List<JSONObject> configCodeList = new ArrayList<JSONObject>();
        for (JSONObject jo : ds_user_configcode) {
            try {
                if ((jo.getInt("t") == showType || showType == -1) && jo.getInt("s") == style && jo.getInt("si") == sizeid) {
                    configCodeList.add(jo);
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        return configCodeList;
    }

    //得到配置信息
    public static SizeConfigInfoBean getCodeSizeConfigInfo(int style, int sizeid) {
        List<JSONObject> codeConfigList = null;
        SizeConfigInfoBean sizeConfigInfoBean = new SizeConfigInfoBean();
        sizeConfigInfoBean.sizeConfigCount = 0;
        sizeConfigInfoBean.sizeConfigItemCount = 0;
        sizeConfigInfoBean.sizeConfigVaildCount = 0;
        int sizeCount = 0;
        int sizeCountSum = 0;
        String[] listName;
        String[] listValue;
        String[] sizeType = new String[3];
        sizeType[0] = "A";
        sizeType[1] = "B";
        sizeType[2] = "C";
        for (int i = 0; i < 3; i++) {//依次取得三种配置类型
            codeConfigList = getConfigCodeByStyle(i, style, sizeid);
            for (int j = 0; j < sizeType.length; j++) {
                //先计算个数
                sizeCount = 0;
                sizeCountSum = 0;
                listName = new String[codeConfigList.size() + 1];
                for (int initM = 0; initM < listName.length; initM++) {
                    listName[initM] = "";
                }
                listValue = new String[codeConfigList.size() + 1];
                for (int initM = 0; initM < listValue.length; initM++) {
                    listValue[initM] = "";
                }
                for (JSONObject jo : codeConfigList) {
                    try {
                        if (jo.getString("st").equals(sizeType[j])) {
                            listName[sizeCount] = jo.getString("sn");
                            listValue[sizeCount] = jo.getString("ct");
                            sizeCount++;
                            sizeCountSum += jo.getInt("ct");
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
                if (sizeCount > sizeConfigInfoBean.sizeConfigItemCount) {
                    sizeConfigInfoBean.sizeConfigItemCount = sizeCount;
                }
                listName[codeConfigList.size()] = String.valueOf(i) + "#" + sizeType[j];//尺码类型
                if (i == 0) {
                    listValue[codeConfigList.size()] = "数量" + sizeType[j];//类型
                } else if (i == 1) {
                    listValue[codeConfigList.size()] = "数值" + sizeType[j];//类型
                } else {
                    listValue[codeConfigList.size()] = "百分比" + sizeType[j];//类型
                }
                if (sizeCount > 0 && sizeCountSum > 0) {
                    sizeConfigInfoBean.sizeConfigVaildCount++;
                    sizeConfigInfoBean.sizeConfigCount++;
                    sizeConfigInfoBean.sizeConfigSetName.add(listName);
                    sizeConfigInfoBean.sizeConfigSetCount.add(listValue);
                }
            }
        }
        if (codeConfigList != null) {
            if (sizeConfigInfoBean.sizeConfigCount < 3) {
                listName = new String[codeConfigList.size() + 1];
                for (int initM = 0; initM < listName.length; initM++) {
                    listName[initM] = "";
                }
                listName[codeConfigList.size()] = "0#" + sizeType[2 - sizeConfigInfoBean.sizeConfigCount];
                listValue = new String[codeConfigList.size() + 1];
                for (int initM = 0; initM < listValue.length; initM++) {
                    listValue[initM] = "";
                }
                listValue[codeConfigList.size()] = "" + sizeType[2 - sizeConfigInfoBean.sizeConfigCount];
                sizeConfigInfoBean.sizeConfigCount++;
                sizeConfigInfoBean.sizeConfigSetName.add(listName);
                sizeConfigInfoBean.sizeConfigSetCount.add(listValue);

            }
        }
        return sizeConfigInfoBean;
    }

    //获取指定商品的订单数量  i_freeze:0非冻洁    1冻洁   其它表示全部
    // color_id  <=0表示忽略   大于零要进行匹配
    //size_sub为空不进行匹配
    public static int getGoodsOrderCountByCall(String account, String code, int color_id, String size_sub, int i_freeze) {
        int goodsordercount = 0;
        JSONObject gf = null;
        boolean bContinue = true;
        LocalSaveOrderListBean orderlist = getGoodsOrdersByCode(CommonDataSets.getIntforString(account), code, true);
        for (LocalSaveOrderListOfColorsBean coloritem : orderlist.getColors()) {
            bContinue = true;
            if (color_id > 0) {
                bContinue = coloritem.getColor_id() == color_id;
            }
            if (bContinue) {
                if (!"".equals(size_sub)) {
                    bContinue = coloritem.getSize_sub_id().equals(size_sub);
                }
                if (bContinue) {
                    if (i_freeze == 0 || i_freeze == 1) {
                        gf = getGoodsFreezeByCodeColor(code, coloritem.getColor_id());
                        if (gf == null) {//未取消款信息
                            if (i_freeze == 0) {
                                goodsordercount = goodsordercount + coloritem.getCount();
                            }
                        } else {
                            if (i_freeze == 1) {
                                goodsordercount = goodsordercount + coloritem.getCount();
                            }
                        }
                    } else {
                        goodsordercount = goodsordercount + coloritem.getCount();
                    }
                }
            }

        }
        /*
        for (JSONObject jo:ds_user_order.values()){
			bContinue=true;
			try {
				if (account.equals(jo.getString("account")) && jo.getString("code").equals(code)){
					if (color_id>0){
						bContinue=jo.getInt("color_id")==color_id;
					}
					if (bContinue){
						if (!"".equals(size_sub)){
							bContinue=jo.getString("size_sub_id").equals(size_sub);
						}
					}
					if (bContinue){
						if (i_freeze==0 || i_freeze==1){
							gf=getGoodsFreezeByCodeColor(code,jo.getInt("color_id"));
							if (gf==null){//未取消款信息
								if (i_freeze==0){
									goodsordercount=goodsordercount+jo.getInt("count");
								}
							}else{
								if (i_freeze==1){
									goodsordercount=goodsordercount+jo.getInt("count");
								}
							}
						}else{
							goodsordercount=goodsordercount+jo.getInt("count");
						}
					}
				}
			} catch (JSONException e) {
				e.printStackTrace();
			}
		}
		*/
        return goodsordercount;
    }

    //判断有未同步的订单数据
    public static JSONArray getOrderNotSync(String account) {
        JSONArray returnList = new JSONArray();
        JSONObject map = null;
        for (LocalSaveOrderListBean orderitem : ds_user_order.values()) {
            try {
                for (LocalSaveOrderListOfColorsBean coloritem : orderitem.getColors()) {
                    if (coloritem.getSync() == 2) {
                        coloritem.setSync(0);
                    }
                    if (coloritem.getSync() == 0) {
                        map = new JSONObject();
                        map.put("account", orderitem.getAccount());
                        map.put("code", orderitem.getCode());
                        map.put("count", coloritem.getSync_count());
                        map.put("dp", coloritem.getSync_dp());
                        map.put("sj", coloritem.getSync_sj());
                        map.put("size_id", coloritem.getSize_id());
                        map.put("size_sub_id", coloritem.getSize_sub_id());
                        map.put("color_id", coloritem.getColor_id());
                        map.put("freeze", coloritem.getFreeze());
                        returnList.put(map);
                    }
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        return returnList;
    }

    public static JSONArray getOrderNotSyncAll(String account) {
        JSONArray returnList = new JSONArray();
        JSONObject map = null;
        for (LocalSaveOrderListBean orderitem : ds_user_order.values()) {
            try {
                for (LocalSaveOrderListOfColorsBean coloritem : orderitem.getColors()) {
                    map = new JSONObject();
                    map.put("account", orderitem.getAccount());
                    map.put("code", orderitem.getCode());
                    map.put("count", coloritem.getSync_count());
                    map.put("dp", coloritem.getSync_dp());
                    map.put("sj", coloritem.getSync_sj());
                    map.put("size_id", coloritem.getSize_id());
                    map.put("size_sub_id", coloritem.getSize_sub_id());
                    map.put("color_id", coloritem.getColor_id());
                    map.put("freeze", coloritem.getFreeze());
                    returnList.put(map);
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        return returnList;
    }

    public static void userDataClearSync(String account, boolean bSync) {
        for (JSONObject jo : ds_user_goods_flag.values()) {
            try {
                if (jo.getInt("sync") == 0) {
                    if (bSync) {
                        jo.put("flag_mark", jo.getString("flag_mark_sync"));
                        jo.put("flag_fh", jo.getString("flag_fh_sync"));
                    }
                    jo.put("sync", 1);
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        for (JSONObject jo : ds_user_goods_display_flag.values()) {
            try {
                if (jo.getInt("sync") == 0) {
                    if (bSync) {
                        jo.put("mark", jo.getString("mark_sync"));
                    }
                    jo.put("sync", 1);
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        for (JSONObject jo : ds_user_order_sizegroup) {
            try {
                if (jo.getInt("sync") == 0) {
                    if (bSync) {
                        jo.put("l", jo.getString("ls"));
                    }
                    jo.put("sync", 1);
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        for (LocalSaveOrderListBean orderitem : ds_user_order.values()) {
            for (LocalSaveOrderListOfColorsBean coloritem : orderitem.getColors()) {
                if (coloritem.getSync() == 0) {
                    if (bSync) {
                        coloritem.setCount(coloritem.getSync_count());
                        coloritem.setCountOld(coloritem.getCount());
                        coloritem.setDp(coloritem.getSync_dp());
                        coloritem.setSj(coloritem.getSync_sj());
                    }
                    coloritem.setSync(1);
                }
            }
        }
        try {
            for (JSONObject jo : ds_user_configcode) {
                if (jo.getInt("y") == 2) {
                    jo.put("y", 1);
                }
                if (jo.getInt("y") == 0) {
                    jo.put("y", 1);
                }
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        ds_config_activity.orderShowConfigSync = false;
        /*
        for (JSONObject jo:ds_user_order.values()){
			try {
				if (account.equals(jo.getString("account")) && jo.getInt("sync")==0){
					if (bSync){
						jo.put("count", jo.getString("sync_count"));
						jo.put("dp", jo.getString("sync_dp"));
						jo.put("sj", jo.getString("sync_sj"));
					}
					jo.put("sync", 1);
				}
			} catch (JSONException e) {
				e.printStackTrace();
			}
		}
		*/
    }

    //把动态数据存到文件中
    public static void saveUserDataToDisk() {

        JSONObject jsonbaseData = new JSONObject();
        List<Object> rsList = new ArrayList<Object>();
        HashMap<String, String> map = new HashMap<String, String>();
        try {
            rsList = new ArrayList<Object>();
            /*
            for (JSONObject jo:ds_user_list.values()){//account,name,priviledge
				map = new HashMap<String, String>();
				map.put("account", jo.getString("account"));
				map.put("name", jo.getString("name"));
				map.put("priviledge", jo.getString("priviledge"));
				rsList.add(map);
			}
			*/
            jsonbaseData.put("shops", rsList);

            rsList = new ArrayList<Object>();
            /*
            for (JSONObject jo:ds_user_configsize.values()){//,,,,,,
				map = new HashMap<String, String>();
				map.put("rownum", jo.getString("rownum"));
				map.put("account", jo.getString("account"));
				map.put("configtype", jo.getString("configtype"));
				map.put("configsizeid", jo.getString("configsizeid"));
				map.put("configsizename", jo.getString("configsizename"));
				map.put("configsizesort", jo.getString("configsizesort"));
				map.put("configcount", jo.getString("configcount"));
				map.put("sync", jo.getString("sync"));
				rsList.add(map);
			}
			*/
            jsonbaseData.put("user_configsize", rsList);

            rsList = new ArrayList<Object>();
            /*
            for (JSONObject jo:ds_user_configmincolor){//code,color,mincount
				map = new HashMap<String, String>();
				map.put("code", jo.getString("code"));
				map.put("color", jo.getString("color"));
				map.put("mincount", jo.getString("mincount"));
				rsList.add(map);
			}
			*/
            jsonbaseData.put("user_configmincolor", (rsList));

            rsList = new ArrayList<Object>();
            for (JSONObject jo : ds_user_goods_flag.values()) {// account,code,flag_mark,flag_fh,wifichange,savetime,sync,sug ( 意见 )  ,read ( 修改通知阅读标志 )
                map = new HashMap<String, String>();
                map.put("account", jo.getString("account"));
                map.put("code", jo.getString("code"));
                map.put("flag_mark", jo.getString("flag_mark"));
                map.put("flag_fh", jo.getString("flag_fh"));
                map.put("flag_mark_sync", jo.getString("flag_mark"));
                map.put("flag_fh_sync", jo.getString("flag_fh"));

                map.put("code_wifichange", jo.getString("code_wifichange"));
                map.put("code_savetime", jo.getString("code_savetime"));

                map.put("sug", jo.getString("sug"));
                map.put("read", jo.getString("read"));

                map.put("sync", jo.getString("sync"));
                rsList.add(map);
            }
            jsonbaseData.put("goods_flag", (rsList));

            rsList = new ArrayList<Object>();
            for (JSONObject jo : ds_user_goods_display_flag.values()) {//  display,mark,mark_sync
                map = new HashMap<String, String>();
                map.put("display", jo.getString("display"));
                map.put("mark", jo.getString("mark"));
                map.put("mark_sync", jo.getString("mark_sync"));
                map.put("sync", jo.getString("sync"));
                rsList.add(map);
            }
            jsonbaseData.put("goods_display", (rsList));

            rsList = new ArrayList<Object>();
            for (JSONObject jo : ds_user_order_sizegroup) {
                map = new HashMap<String, String>();
                map.put("c", jo.getString("c"));
                map.put("t", jo.getString("t"));
                map.put("s", jo.getString("s"));
                map.put("l", jo.getString("l"));
                map.put("ls", jo.getString("ls"));
                map.put("sync", jo.getString("sync"));
                rsList.add(map);
            }
            jsonbaseData.put("orderssizegroup", (rsList));

            rsList = new ArrayList<Object>();
            for (LocalSaveOrderListBean jo : ds_user_order.values()) {//account,code,count,dp,sj,size_id,size_sub_id,color_id,freeze,sync
                for (LocalSaveOrderListOfColorsBean color : jo.getColors()) {
                    map = new HashMap<String, String>();
                    map.put("account", "" + jo.getAccount());
                    map.put("code", jo.getCode());
                    map.put("count", "" + color.getCount());
                    map.put("dp", "" + color.getDp());
                    map.put("sj", "" + color.getSj());
                    map.put("sync_count", "" + color.getSync_count());
                    map.put("sync_dp", "" + color.getSync_dp());
                    map.put("sync_sj", "" + color.getSync_sj());
                    map.put("size_id", "" + color.getSize_id());
                    map.put("size_sub_id", color.getSize_sub_id());
                    map.put("color_id", "" + color.getColor_id());
                    map.put("freeze", "" + color.getFreeze());
                    map.put("sync", "" + color.getSync());
                    rsList.add(map);
                }
            }
            jsonbaseData.put("orders", (rsList));
            rsList = new ArrayList<Object>();
            for (JSONObject jo : ds_user_configcode) {
                map = new HashMap<String, String>();
                map.put("a", jo.getString("a"));
                map.put("t", jo.getString("t"));
                map.put("s", jo.getString("s"));
                map.put("st", jo.getString("st"));
                map.put("si", jo.getString("si"));
                map.put("sn", jo.getString("sn"));
                map.put("sr", jo.getString("sr"));
                map.put("ct", jo.getString("ct"));
                map.put("y", jo.getString("y"));//已经同步标记
                rsList.add(map);
            }
            jsonbaseData.put("configcode", (rsList));

            rsList = new ArrayList<Object>();
            /*
            for (JSONObject jo:ds_user_areasort_groupbycode){
				map = new HashMap<String, String>();
				map.put("pm", jo.getString("pm"));
				map.put("code", jo.getString("code"));
				map.put("sl", jo.getString("sl"));
				rsList.add(map);
			}
			*/
            jsonbaseData.put("ordersbyarea", (rsList));

            rsList = new ArrayList<Object>();
            map = new HashMap<String, String>();
            map.put("ossync", ds_config_activity.orderShowConfigSync ? "1" : "0");
            map.put("account", ds_config_activity.orderShowAccount);
            map.put("ospic", ds_config_activity.orderShowPic ? "1" : "0");
            map.put("osseason", ds_config_activity.orderShow_Season ? "1" : "0");
            map.put("osserial", ds_config_activity.orderShow_Serial ? "1" : "0");
            map.put("oswave", ds_config_activity.orderShow_Wave ? "1" : "0");
            map.put("ostype", ds_config_activity.orderShow_Type ? "1" : "0");
            map.put("osstyle", ds_config_activity.orderShow_Style ? "1" : "0");
            map.put("osstylepos", ds_config_activity.orderShow_StylePos ? "1" : "0");
            map.put("osprice", ds_config_activity.orderShow_Price ? "1" : "0");
            map.put("oscolor", ds_config_activity.orderShow_Color ? "1" : "0");
            rsList.add(map);
            jsonbaseData.put("data_orderconfig", (rsList));

            FileWriter writer = null;
            String sFile = CommonDataSets.CLIENT_STRONGPATH + "/publicuserdata";
            writer = new FileWriter(sFile, false);
            writer.write(jsonbaseData.toString());
            writer.close();
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    //从本地存储中读取用户数据
    public static void readLocalUserDataToReset() {
        String res = "";
        try {
            FileInputStream fin = new FileInputStream(CommonDataSets.CLIENT_STRONGPATH + "/publicuserdata");
            int length = fin.available();
            byte[] buffer = new byte[length];
            fin.read(buffer);
            res = EncodingUtils.getString(buffer, "GB2312");
            fin.close();
            JSONObject jsonData = new JSONObject(res);
            //序列化到内存
            CommonDataSets.saveToCacheUserData(jsonData, false);
        } catch (Exception e) {
            Log.e("", e.getMessage());
            //e.printStackTrace();
        }
    }

    public static void saveToCacheUserData(JSONObject jsonData, boolean readRemote) {
        try {
            ds_user_list.clear();
            if (readRemote) {
                Log.d("", "shops->" + jsonData.getJSONArray("shops").length());
                populateObject(jsonData.getJSONArray("shops"), ds_user_list, "account");
                JSONObject objBoardInfo = jsonData.getJSONObject("boardInfo");
                ds_user_plan_all.setItem0(objBoardInfo.getString("pa"));
                ds_user_plan_all.setItem1(objBoardInfo.getString("pc"));
                ds_user_plan_all.setItem2(objBoardInfo.getString("ps"));
                ds_user_plan.clear();
                populateObject(jsonData.getJSONArray("plans"), ds_user_plan);
                ds_user_configmincolor.clear();
                //Log.d("", "user_configmincolor->"+jsonData.getJSONArray("user_configmincolor").length());
                populateObject(jsonData.getJSONArray("user_configmincolor"), ds_user_configmincolor);
                ds_user_suggest.clear();
                populateObject(jsonData.getJSONArray("configsuggest"), ds_user_suggest);

                ds_user_areasort_groupbycode.clear();
                populateObject(jsonData.getJSONArray("ordersbyarea"), ds_user_areasort_groupbycode);
            }

            ds_user_goods_flag.clear();
            //Log.d("", "goods_flag->"+jsonData.getJSONArray("goods_flag").length());
            populateObject(jsonData.getJSONArray("goods_flag"), ds_user_goods_flag, "code");
            if (readRemote) {
                for (JSONObject jo : ds_user_goods_flag.values()) {
                    try {
                        jo.put("flag_mark_sync", jo.getString("flag_mark"));
                        jo.put("flag_fh_sync", jo.getString("flag_fh"));
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            }

            ds_user_goods_display_flag.clear();
            populateObject(jsonData.getJSONArray("goods_display"), ds_user_goods_display_flag, "display");
            if (readRemote) {
                for (JSONObject jo : ds_user_goods_display_flag.values()) {
                    try {
                        jo.put("mark_sync", jo.getString("mark"));
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            }
            //订单尺码组
            ds_user_order_sizegroup.clear();
            populateObject(jsonData.getJSONArray("orderssizegroup"), ds_user_order_sizegroup);
            //用户订单数据
            ds_user_order.clear();
            //Log.d("", "orders->"+jsonData.getJSONArray("orders").length());
            JSONArray arrayForOrder = jsonData.getJSONArray("orders");
            int i_arrayForOrder = arrayForOrder.length();
            JSONObject object = null;
            LocalSaveOrderListBean orderBeanTemp = null;
            LocalSaveOrderListOfColorsBean colorsBean = null;
            for (int i = 0; i < i_arrayForOrder; i++) {
                object = (JSONObject) arrayForOrder.get(i);
                try {
                    if (orderBeanTemp == null) {
                        orderBeanTemp = new LocalSaveOrderListBean();
                        orderBeanTemp.setAccount(object.getInt("account"));
                        orderBeanTemp.setCode(object.getString("code"));
                    } else if (!orderBeanTemp.getCode().equals(object.get("code"))) {
                        ds_user_order.put(orderBeanTemp.getAccount() + "#" + orderBeanTemp.getCode(), orderBeanTemp);
                        orderBeanTemp = new LocalSaveOrderListBean();
                        orderBeanTemp.setAccount(object.getInt("account"));
                        orderBeanTemp.setCode(object.getString("code"));

                    }
                    colorsBean = new LocalSaveOrderListOfColorsBean();
                    colorsBean.setColor_id(object.getInt("color_id"));
                    colorsBean.setSize_id(object.getInt("size_id"));
                    colorsBean.setSize_sub_id(object.getString("size_sub_id"));
                    colorsBean.setCount(object.getInt("count"));
                    colorsBean.setDp(0);
                    colorsBean.setSj(0);
                    colorsBean.setFreeze(object.getInt("freeze"));
                    if (readRemote) {
                        colorsBean.setSync_count(object.getInt("count"));
                        colorsBean.setSync_dp(0);
                        colorsBean.setSync_sj(0);
                    } else {
                        colorsBean.setSync_count(object.getInt("sync_count"));
                        colorsBean.setSync_dp(0);
                        colorsBean.setSync_sj(0);
                    }
                    colorsBean.setSync(object.getInt("sync"));
                    orderBeanTemp.getColors().add(colorsBean);
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
            if (orderBeanTemp != null) {
                ds_user_order.put(orderBeanTemp.getAccount() + "#" + orderBeanTemp.getCode(), orderBeanTemp);
            }

            ds_user_configcode.clear();
            populateObject(jsonData.getJSONArray("configcode"), ds_user_configcode);

            //Log.d("", "readRemote->"+readRemote);
            if (!readRemote) {
                JSONArray orderConfig = jsonData.getJSONArray("data_orderconfig");
                if (orderConfig != null) {
                    if (orderConfig.length() > 0) {
                        object = (JSONObject) orderConfig.get(0);
                        ds_config_activity.orderShowConfigSync = object.getString("ossync").equals("1");
                        ds_config_activity.orderShowAccount = object.getString("account");
                        ds_config_activity.orderShowPic = object.getString("ospic").equals("1");
                        ds_config_activity.orderShow_Season = object.getString("osseason").equals("1");
                        ds_config_activity.orderShow_Serial = object.getString("osserial").equals("1");
                        ds_config_activity.orderShow_Wave = object.getString("oswave").equals("1");
                        ds_config_activity.orderShow_Type = object.getString("ostype").equals("1");
                        ds_config_activity.orderShow_Style = object.getString("osstyle").equals("1");
                        ds_config_activity.orderShow_StylePos = object.getString("osstylepos").equals("1");
                        ds_config_activity.orderShow_Price = object.getString("osprice").equals("1");
                        ds_config_activity.orderShow_Color = object.getString("oscolor").equals("1");
                    }
                }
            }
            saveUserDataToDisk();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static JSONObject getJSONObjectByMap(List<JSONObject> map, String keyFieldName, String key) {
        for (JSONObject jo : map) {
            try {
                if (jo.getString(keyFieldName).equals(key)) {
                    return jo;
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        return null;
    }

    public static JSONObject getJSONObjectByMap(Map<String, JSONObject> map, String key) {
        return map.get(key);
    }

    public static String getJSONObjectValueByMap(Map<String, JSONObject> map, String key, String valuename) {
        JSONObject jsonobj = getJSONObjectByMap(map, key);
        if (jsonobj != null) {
            try {
                return jsonobj.getString(valuename);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return "";
    }

    private static final class JsonWrap {
        JSONObject json;

        public JsonWrap(JSONObject json) {
            this.json = json;
        }

        JSONArray getJSONArray(String tag) {
            try {
                JSONArray array = json.getJSONArray(tag);
                return array;
            } catch (JSONException e) {
                Log.w("json-->", "no data found for " + tag);
                return new JSONArray();
            }
        }
    }

    private static void populateString(JSONArray array, Map<String, String> map, String tag) throws JSONException {
        if (array != null) {
            int len = array.length();
            for (int i = 0; i < len; i++) {
                JSONObject object = (JSONObject) array.get(i);
                map.put(object.getString("id"), object.getString(tag));
            }
        }
    }

    private static void populateObject(JSONArray array, Map<String, JSONObject> map) throws JSONException {
        if (array != null) {
            int len = array.length();
            for (int i = 0; i < len; i++) {
                JSONObject object = (JSONObject) array.get(i);
                map.put(object.getString("id"), object);
            }
        }
    }

    public static void populateObject(JSONArray array, List<JSONObject> map) throws JSONException {
        if (array != null) {
            int len = array.length();
            for (int i = 0; i < len; i++) {
                JSONObject object = (JSONObject) array.get(i);
                map.add(object);
            }
        }
    }

    private static void populateObject(JSONArray array, List<JSONObject> map, String sortname) throws JSONException {
        if (array != null) {
            int len = array.length();
            int showindex = 0;
            for (int i = 0; i < len; i++) {
                JSONObject object = (JSONObject) array.get(i);
                showindex = 0;
                for (JSONObject jo : map) {
                    if (object.getInt(sortname) >= jo.getInt(sortname)) {
                        showindex++;
                    } else {
                        break;
                    }
                }
                map.add(showindex, object);
            }
        }
    }

    private static void populateObject(JSONArray array, Map<String, JSONObject> map, String code) throws JSONException {
        if (array != null) {
            int len = array.length();
            for (int i = 0; i < len; i++) {
                JSONObject object = (JSONObject) array.get(i);
                map.put(object.getString(code), object);
            }
        }
    }

    //按照code排序
    private static void populateCode(JSONArray array, Map<Integer, JSONObject> map) throws JSONException {
        if (array != null) {
            int len = array.length();
            for (int i = 0; i < len; i++) {
                JSONObject object = (JSONObject) array.get(i);
                map.put(Integer.parseInt(object.getString("code")), object);
            }
        }
    }


    private static void populateObjectForPair(JSONArray array, Map<String, JSONObject> map, String code, String brandId) throws JSONException {
        if (array != null) {
            int len = array.length();
            for (int i = 0; i < len; i++) {
                JSONObject object = (JSONObject) array.get(i);
                for (int j = 1; j <= 8; j++) {
                    String productCode = object.getString("code" + j);
                    if (productCode != null && !TextUtils.isEmpty(productCode)) {
                        JSONObject goodInfo = getGoodsByCode(productCode);

                    }
                }


                map.put(object.getString(code), object);
            }
        }
    }

//	private static void populateObjectStrSort(JSONArray array, List<JSONObject> map,String sortname) throws JSONException {
//		if (array!=null){
//			int len = array.length();
//			int showindex=0;
//			for (int i = 0; i < len; i++) {
//				JSONObject object = (JSONObject) array.get(i);
//				showindex=0;
//				for (JSONObject jo:map){
//					if (object.getString(sortname).compareTo(jo.getString(sortname))>=0){
//						showindex++;
//					}else{
//						break;
//					}
//				}
//				map.add(showindex, object);
//			}
//		}
//	}

    private static void populateObjectByIndex(JSONArray array, Map<String, JSONObject> map) throws JSONException {
        if (array != null) {
            int len = array.length();
            for (int i = 0; i < len; i++) {
                JSONObject object = (JSONObject) array.get(i);
                map.put(String.valueOf(i), object);//用序号来代替
            }
        }
    }

    public static int getIntforString(String strdata) {
        try {
            return (int) Float.parseFloat(strdata);
        } catch (Exception e) {
            // TODO: handle exception
        }
        return 0;
    }

    public static int getIntforString(String strdata, int moren) {
        try {
            return (int) Float.parseFloat(strdata);
        } catch (Exception e) {
            // TODO: handle exception
        }
        return moren;
    }

    public static String getDoubleForString(double a) {
        if (a % 1 == 0) {
            BigDecimal bigDecimal = new BigDecimal(a);
            return bigDecimal.toString();
        } else {
            return String.format("%.2f", a);
        }
    }

    public static String getColorName(String colorId) {
        String colorName = "";
        for (JSONObject jo : CommonDataSets.ds_colors.values()) {
            try {
                if (colorId.equals(jo.getString("id"))) {
                    colorName = jo.getString("color");
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
        return colorName;
    }
}
